package com.tianbao54.factory.abstractx;

import org.omg.CORBA.PUBLIC_MEMBER;

abstract class Compute {

    public abstract String getRAM ();
    public abstract String getHDD ();
    public abstract String getCPU ();

    @Override
    public String toString() {
        return "RAM= "+this.getRAM()+", HDD="+this.getHDD()+", CPU="+this.getCPU();
    }
}

class PC extends Compute {

    private String ram;
    private String hdd;
    private String cpu;

    PC (String ram,String hdd,String cpu) {
        this.ram = ram;
        this.hdd = hdd;
        this.cpu = cpu;
    }

    @Override
    public String getRAM() {
        return this.ram;
    }

    @Override
    public String getHDD() {
        return this.hdd;
    }

    @Override
    public String getCPU() {
        return this.cpu;
    }
}

class Server extends Compute {

    private String ram;
    private String hdd;
    private String cpu;

    public Server(String ram, String hdd, String cpu) {
        this.ram = ram;
        this.hdd = hdd;
        this.cpu = cpu;
    }

    @Override
    public String getRAM() {
        return this.ram;
    }

    @Override
    public String getHDD() {
        return this.hdd;
    }

    @Override
    public String getCPU() {
        return this.cpu;
    }
}

abstract class AbstractComputeFactory {

    public abstract Compute create ();
}

class PCFactory extends AbstractComputeFactory {

    private String cpu;
    private String hdd;
    private String ram;

    public PCFactory(String cpu, String hdd, String ram) {
        this.cpu = cpu;
        this.hdd = hdd;
        this.ram = ram;
    }

    @Override
    public Compute create() {
        return new PC(ram,hdd,cpu);
    }
}

class ServerFactory extends AbstractComputeFactory {

    private String ram;
    private String hdd;
    private String cpu;

    public ServerFactory(String ram, String hdd, String cpu) {
        this.ram = ram;
        this.hdd = hdd;
        this.cpu = cpu;
    }

    @Override
    public Compute create() {
        return new Server(ram,hdd,cpu);
    }
}

class ComputeFactory {

    public static Compute getCompute (AbstractComputeFactory factory) {
        return factory.create();
    }
}

public class AbstractFactory {

    public static void main(String[] args) {

        Compute compute = ComputeFactory.getCompute(new ServerFactory("12","500","Atom"));
        Compute pc = ComputeFactory.getCompute(new PCFactory("12","500","Intel"));
        System.out.println("pc = " + pc);
        System.out.println("server = " + compute);

    }
}
